<?php
namespace app\admin\controller;

class Department extends Adm
{
	use \app\admin\traits\Curd;
    public function index()
    {
    	return $this->fetch();
    }
    protected function _add()
    {
        $cates = \app\admin\model\cate::select()->toArray();
        $cates = $this->listtotreearr($cates,'parent_id');
        $this->assign(get_defined_vars());
    }
    private function listtotreearr(
        $lists,
        $parent_field='parent_id',
        $parent_id=0,
        $son_field='children'
    )
    {
        $list = [];
        $rows = $lists;
        foreach($rows as $k=>$v)
        {
            $data = $v;
            $data['children'] = [];
            if($v['parent_id']==$parent_id)
            {
                unset($lists[$k]);
                $sons = $this->listtotreearr($lists,$parent_field,$v['id']);
                foreach($sons as $i=>$item){
                    array_push($data['children'], $item);
                }
                array_push($list, $data);
            }
        }
        return $list;
    }
    /**
     * [data 全部数据]
     * @return [type] [description]
     */
    function data()
    {
        header('Content-type:application/json;charset:utf-8;');
        echo '{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"code":0,"msg":null,"count":null,"data":[{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"1","deptName":"济南总公司","address":"山东济南","parentId":"0","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":1},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"10","deptName":"设计部","address":"山东济南","parentId":"8","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"1316361008259792896","deptName":"软件部","address":"山东济南","parentId":"1316360459930042368","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":1},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"1316361192645591040","deptName":"市场部","address":"山东济南","parentId":"1316360459930042368","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":1},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"3","deptName":"杭州分公司","address":"浙江杭州","parentId":"1","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":1},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"4","deptName":"软件部","address":"山东济南","parentId":"2","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":2},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"5","deptName":"市场部","address":"山东济南","parentId":"2","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":2},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"6","deptName":"软件部","address":"山东济南","parentId":"3","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"7","deptName":"设计部","address":"山东济南","parentId":"3","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"8","deptName":"深圳分公司","address":"山东济南","parentId":"1","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"9","deptName":"软件部","address":"山东济南","parentId":"8","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3}]}';
    }
    function tree()
    {
        header('Content-type:application/json;charset:utf-8');
        return '{"status":{"code":200,"message":"默认"},"data":[{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"1","deptName":"济南总公司","address":"山东济南","parentId":"0","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":1},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"10","deptName":"设计部","address":"山东济南","parentId":"8","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"1316361008259792896","deptName":"软件部","address":"山东济南","parentId":"1316360459930042368","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":1},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"1316361192645591040","deptName":"市场部","address":"山东济南","parentId":"1316360459930042368","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":1},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"3","deptName":"杭州分公司","address":"浙江杭州","parentId":"1","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":1},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"4","deptName":"软件部","address":"山东济南","parentId":"2","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":2},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"5","deptName":"市场部","address":"山东济南","parentId":"2","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":2},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"6","deptName":"软件部","address":"山东济南","parentId":"3","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"7","deptName":"设计部","address":"山东济南","parentId":"3","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"8","deptName":"深圳分公司","address":"山东济南","parentId":"1","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3},{"createTime":null,"createBy":null,"createName":null,"updateTime":null,"updateBy":null,"updateName":null,"remark":null,"params":null,"deptId":"9","deptName":"软件部","address":"山东济南","parentId":"8","leader":"就眠仪式","phone":"15553726531","email":"pearadmin@gmail.com","status":"0","sort":3}]}';
    }
}
